package dkzcm.club.article.domain.service.impl;

import com.alibaba.fastjson.JSON;
import dkzcm.club.article.domain.convert.ArticleCategoryConvert;
import dkzcm.club.article.domain.entity.ArticleCategoryBO;
import dkzcm.club.article.domain.service.ArticleCategoryDomainService;
import dkzcm.club.article.infra.basic.entity.ArticleCategory;
import dkzcm.club.article.infra.basic.service.ArticleCategoryService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @desc:
 * @author: xk
 * @version: 1.0
 * Create by 2024/11/10 15:08
 */
@Slf4j
@Service
public class ArticleCategoryDomainServiceImpl implements ArticleCategoryDomainService {
    @Resource
    private ArticleCategoryService articleCategoryService;

    @Override
    public void add(ArticleCategoryBO articleCategoryBO) {
        if (log.isInfoEnabled()) {
            log.info("article add articleCategoryBO:{}", JSON.toJSONString(articleCategoryBO));
        }
        ArticleCategory articleCategory = ArticleCategoryConvert.INSTANCE
                .convertArticleCategory(articleCategoryBO);
        articleCategoryService.insert(articleCategory);


    }

    @Override
    public List<ArticleCategoryBO> queryPrimaryCategory() {
        List<ArticleCategory> articleCategoryList = articleCategoryService.queryPrimaryCategory();
        List<ArticleCategoryBO> articleCategoryBOList = ArticleCategoryConvert.INSTANCE.convertArticleCategoryList(articleCategoryList);
        if (log.isInfoEnabled()) {
            log.info("queryPrimaryCategory:{}" + JSON.toJSONString(articleCategoryBOList));
        }
        return articleCategoryBOList;
    }
}
